package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/purchaseListGoods")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    //进货单保存
    @PostMapping("/save")
    public ServiceVO save(PurchaseList purchaseList, String purchaseListGoodsStr){
       this.purchaseService.savePurchaseList(purchaseList,purchaseListGoodsStr);
       return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    //进货单列表展示
    @PostMapping("/list")
    public Map<String,Object> list(String purchaseNumber, Integer supplierId, Integer state, String sTime,String eTime){
        return purchaseService.getPurchaseList(purchaseNumber,supplierId,state,sTime,eTime);
    }
//    http://localhost:8080/purchaseListGoods/goodsList
    @PostMapping("/goodsList")
    public Map<Object, Object> goodsList(Integer purchaseListId){
        return purchaseService.getPurchaseListGoods(purchaseListId);
    }
    //进货单删除
    @PostMapping("/delete")
    public ServiceVO delete(Integer purchaseListId) {
        this.purchaseService.purchaseDelete(purchaseListId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    //支付结算（修改进货单付款状态）http://localhost:8080/purchaseListGoods/updateState
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer purchaseListId){
        this.purchaseService.updateState(purchaseListId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    @PostMapping("/count")
    public List<PurchaseList> getCount(String sTime, String eTime , Integer goodsTypeId, String codeOrName){
        return purchaseService.getCount(sTime,eTime,goodsTypeId,codeOrName);
    }
}
